package com.storm.auth.behavior.factory

import com.storm.auth.behavior.UserEntity
import com.storm.auth.mapper.ResourceMapper
import com.storm.auth.mapper.UserMapper
import com.storm.auth.mapper.UserRoleMapper
import org.springframework.stereotype.Component

@Component
class UserEntityFactory(
    val userMapper: UserMapper,
    val userRoleMapper: UserRoleMapper,
    val resourceMapper: ResourceMapper,
) {

    /**
     * 根据用户id获取用户
     */
    fun getUserEntityById(id:String):UserEntity{
        return getUserEntity(id = id)
    }

    /**
     * 根据用户手机号获取用户
     */
    fun getUserEntityByPhone(phone:String):UserEntity{
        return getUserEntity( phone = phone)
    }

    /**
     * 根据用户名获取用户
     */
    fun getUserEntityByUsername(username:String):UserEntity{
        return getUserEntity(username = username)
    }

    /**
     * 获取用户实体
     */
    private fun getUserEntity(id: String? = null, username: String? = null, phone: String? = null):UserEntity {
        return UserEntity(userMapper, userRoleMapper, resourceMapper, username = username)
    }

}